<?php
/**
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-2-17
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>轩辕商城-注册</title>
<link rel="stylesheet" type="text/css" href="<?php echo CSS_URL;?>register.css" />
<script>

	$(function (){
		/*验证码*/
		$("#submit").attr("disabled",true);
		$("#yzm_check").click(function(){
			var yzm = $("#yzm_val").val();
			$.ajax({
				url:'./index.php?r=user/checkTelCode',
				data:{'yzm':yzm},
				type:'post',
				success:function(data){
					if(data == 1){
						alert('验证通过');
						$("#submit").attr("disabled",false);
					}else{
						alert('验证错误');
					}
				},
				error:function(){
					alert('提交失败');
				}	
			});
		});
		var wait = 60;
		$("#yzm_tel").click(function (){
			var tel = $("#User_user_tel").val();
			reg=/^(\+\d{2,3}\-)?\d{11}$/; 
			if(reg.test(tel)){
				$("#yzmyzm").show();
				time($(this));
				$.ajax({
					url:'./index.php?r=user/yzm&tel='+tel,
					type:'post',
					success:function (data){
//						alert(data);
					},
					error:function (){
						alert('操作失败');
					}
				});
			}else{
				alert('手机号格式错误');
			}
		});
			function time(o){
				if(wait == 0){
					o.css("background","#b30000");
					o.attr("disabled",false);
					o.val("获取验证码");
					wait = 60;
				}else{
					o.attr("disabled",true);
					o.css("background","#ccc");
					o.val(wait+"秒后重新获取");
					wait--;
					setTimeout(function(){
						time(o);
					},1000)
				}
			}
		
		
		$("#code").blur(function(){
			var a = getFormJson("#yw0");
			$.ajax({
				url:'./index.php?r=user/register',
				type:'post',
				data:{type:"input_data",I:a},
				dataType:'json',
				success:function (data){
					(data == 0)? $("#fuck span").addClass("red").empty().text("验证码错误"):$("#fuck span").addClass("red").empty().text("验证通过");
				},
				error:function(){
					alert('error');
				},
			});
			function getFormJson(form){
				var o = {};
				var a = $(form).serializeArray();
				$.each(a,function (){
					if(o[this.name] !== undefined){
						(!o[this.name].push)? o[this.name] = [o[this.name]] : o[this.name].push(this.value || '');
					}else{
						o[this.name] = this.value || '';
					}
				});
				return o;
			}
		});
		$("#User_user_hobby input").last().attr("checked","checked");
		$("#more").click(function (){
		
			$("#hidden").toggle(100);
		});



		$("#User_role_id").bind('change',function (){
			var selValue = $("#User_role_id option:selected").text();
			if(selValue == "商家"){
				$("#info").show();
			}else{
				$("#info").hide();
			}

			$("#submit").click(function (){
				if($("#info").css("display") == "block"){
					if($("#User_sel_name").val() == '' || $("#User_sel_number").val() == ''){
						alert("商家的营业执照信息不得为空");
						if($("#User_sel_name").val() == ''){
							$("#User_sel_name").focus();
						}
						if($("#User_sel_number").val() == ''){
							$("#User_sel_number").focus();
						}
						return false;
					}
				}
			})
		})
	})
</script>
</head>
<body>
<div>
	<?php //include("header.php"); ?>
		<div id="content">
			<div id="header">
				<div id="h_info">
					<div id="left"><a href="index.php"><img src="<?php echo IMG_URL;?>xy2.png" alt="轩辕" title="轩辕商城" /></a></div>
					<div id="search">
					<dl>
						<dt>
						    <dd>
								<input type="text" name="search" placeholder="请输入关键字进行搜索" class="search" />
								<input type="submit" name="send" value="搜索" class="submit" />
							</dd>
						</dt>
					</dl>
					</div>
				</div>
			</div>
			
			<div id="register">
			<?php $form = $this->beginWidget('CActiveForm',array(
				'enableClientValidation'=>true,
				'clientOptions'=>array(
					'validateOnSubmit'=>true,
				),
			)); ?>
				<h2>注册中心</h2>
				<dl>
					<dd>
						<?php echo @$form -> labelEx($user_model,'user_name')?>
						<!--<input type="text" name="username" class="text" />-->
						<?php echo $form -> textField($user_model,'user_name',array('class'=>'text'))?> <span class="red"><?php echo $form->error($user_model,'user_name');?></span>
					</dd>
					<dd><?php echo $form -> labelEx($user_model,'user_password')?>
						<!--<input type="password" name="password" class="text" />-->
						<?php echo $form -> passwordField($user_model,'user_password',array('class'=>'text'))?> <span class="red"><?php echo $form->error($user_model,'user_password');?></span>
					</dd>
					<dd><?php echo $form -> labelEx($user_model,'user_pass_confirm')?> *
						<?php echo $form -> passwordField($user_model,'user_password_confirm',array('class'=>'text','id'=>"user_password_confirm"))?> <span class="red"><?php echo $form->error($user_model,'user_password_confirm');?></span>
					</dd>
					<dd><?php echo $form -> labelEx($user_model,'user_email')?> *
						<?php echo $form -> textField($user_model,'user_email',array('class'=>'text'))?> <span class="red"><?php echo $form->error($user_model,'user_email');?></span>
					</dd>
					<dd><?php echo $form -> labelEx($user_model,'user_question')?> *
						<?php echo $form->DropDownList($user_model,'user_question',$question,array("style"=>"width:170px","class"=>"text"))?> <span class="red"><?php echo $form->error($user_model,'user_question');?></span>
					</dd>
					<dd><?php echo $form -> label($user_model,'user_answer')?> *
						<?php echo $form -> textField($user_model,'user_answer',array('class'=>'text'))?> <span class="red"><?php echo $form->error($user_model,'user_answer');?></span>
					</dd>
					<dd><?php echo $form -> labelEx($user_model,'role_id')?> *
						<?php echo $form->DropDownList($user_model,'role_id',$role_id,array("style"=>"width:170px","class"=>"text",'options'=>array('6'=>array('selected'=>true))))?> 
					</dd>
					<dd id="info" style="display: none">
						<?php echo $form -> labelEx($user_model,'sel_name')?> *
						<?php echo $form -> textField($user_model,'sel_name',array('class'=>'text'))?> 
						<?php echo $form -> labelEx($user_model,'sel_number')?> *
						<?php echo $form -> textField($user_model,'sel_number',array('class'=>'text'))?>
					</dd>
					<dd><?php echo $form -> labelEx($user_model,'user_tel',array('id'=>'teltel'))?>&nbsp;&nbsp;
							<?php echo $form -> textField($user_model,'user_tel',array('class'=>'text',"maxlength"=>11,'style'=>'width:100px'))?> <span class="red"><?php echo $form->error($user_model,'user_tel');?></span><input type="button" id="yzm_tel" value="获取验证码"  style="height:35px;width:100px;background:#b30000;color:#fff;border:none;cursor:pointer;font-size:13px;font-family:微软雅黑;"/>
					</dd>
					<dd id="yzmyzm" style="display: none">手机验证码&nbsp;&nbsp;
							<input type="text" class="text" style="width:70px;" id="yzm_val"  maxlength=4  /><input type="button" id="yzm_check" value="验证"  style="margin-left:10px;height:35px;width:100px;background:#b30000;color:#fff;border:none;cursor:pointer;font-size:13px;font-family:微软雅黑;"/>
					</dd>
					<dd style="color:#666;cursor:pointer;display:inline;"  id="more">展示更多选项>></dd>
					<div style="display: none" id="hidden">
						
						<dd><?php echo $form -> labelEx($user_model,'user_phone')?>&nbsp;&nbsp;
							<?php echo $form -> textField($user_model,'user_phone',array('class'=>'text'))?> <span class="red"><?php echo $form->error($user_model,'user_phone');?></span>
						</dd>
						<dd><?php echo $form -> labelEx($user_model,'user_it')?>&nbsp;&nbsp;
							<?php echo $form -> textField($user_model,'user_it',array('class'=>'text'))?> <span class="red"><?php echo $form->error($user_model,'user_it');?></span>
						</dd>
						<dd><?php echo $form -> labelEx($user_model,'user_birth')?>&nbsp;&nbsp;
							<?php echo $form -> textField($user_model,'user_birth',array('class'=>'text'))?> <span class="red">( 年/月/日)</span>
						</dd>
						<dd><?php echo $form -> labelEx($user_model,'user_addr')?>&nbsp;&nbsp;
							<?php echo $form -> textField($user_model,'user_addr',array('class'=>'text'))?> 
						</dd>
						<dd><?php echo $form -> labelEx($user_model,'user_job')?>&nbsp;&nbsp;
							<?php echo $form -> dropDownList($user_model,'user_job',$job,array("class"=>"text","style"=>"width:170px;"));?>
						</dd>
						<dd><?php echo $form -> labelEx($user_model,'user_hobby')?>&nbsp;&nbsp;
							<?php echo $form -> checkBoxList($user_model,'user_hobby',$hobby,array("separator"=>"&nbsp;"));?> <span class="red"><?php echo $form->error($user_model,'user_hobby');?></span>
						</dd>
					</div>
					<dd  id="fuck"><?php echo $form -> labelEx($user_model,'code')?>&nbsp;&nbsp;<input type="text" class="text code"  name="code"  id="code" /><img src="./index.php?r=user/VerifyCode"  onclick="this.src='./index.php?r=user/VerifyCode&v='+Math.random();" id="yw1" /> <span id="red"></span></dd>
					<dd><?php echo $form -> labelEx($user_model,'user_sex')?>&nbsp;&nbsp;
						<?php echo $form->radiobuttonList($user_model,'user_sex',$sex,array("class"=>"sex",'separator'=>'&nbsp;&nbsp;'));?> 
					</dd>
					<dd><input type="submit" name="send" value="注册" class="text submit" id="submit"  /><span class="red">(必须进行短信验证)</dd>
				</dl>
			<?php $this->endwidget(); ?>
			</div>
		</div>		
		<?php //include("guide.php"); ?>
		<?php //include("footer.php"); ?>
	</div>
</body>
</html>